﻿<UserControl x:Class="TeamProjectManager.Modules.WorkItemConfiguration.WorkItemCategoriesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="clr-namespace:TeamProjectManager.Common.Infrastructure;assembly=TeamProjectManager.Common"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Text="This functionality is not supported in the version of the currently selected Team Project Collection: TFS 2010 or higher is required." TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding Path=TfsUnsupportedVisibility}" />

        <TabControl Visibility="{Binding Path=TfsSupportedVisibility}">

            <TabItem Header="Export / Edit" i:HelpProvider.HelpContent="Allows you to export the work item categories to XML files and edit them in-place.">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Button Grid.Row="0" Content="Get Work Item Categories" Margin="0,5,0,5" Command="{Binding Path=GetWorkItemCategoriesXmlCommand}" />
                    <DataGrid Grid.Row="1" ItemsSource="{Binding Path=WorkItemCategoriesXml}" IsReadOnly="True" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" x:Name="workItemCategoriesXmlDataGrid" SelectionChanged="workItemCategoriesXmlDataGrid_SelectionChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Team Project" Binding="{Binding Path=TeamProject.Name}" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <WrapPanel Grid.Row="2" Margin="0,5,0,0">
                        <Button Content="Export" Command="{Binding Path=ExportSelectedWorkItemCategoriesXmlCommand}" />
                        <Button Content="Edit..." Margin="5,0,0,0" Command="{Binding Path=EditSelectedWorkItemCategoriesXmlCommand}" />
                        <Button Content="Transform..." Margin="5,0,0,0" Command="{Binding Path=TransformSelectedWorkItemCategoriesXmlCommand}" />
                    </WrapPanel>
                </Grid>
            </TabItem>

            <TabItem Header="View / Delete" i:HelpProvider.HelpContent="Allows you to get an overview of all work item categories across Team Projects, and the work items that belong to them. You can even delete work item categories from Team Projects.">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Button Grid.Row="0" Content="Get Work Item Categories" Margin="0,5,0,5" Command="{Binding Path=GetWorkItemCategoriesCommand}" />
                    <DataGrid Grid.Row="1" ItemsSource="{Binding Path=WorkItemCategories}" IsReadOnly="True" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" x:Name="workItemCategoriesDataGrid" SelectionChanged="workItemCategoriesDataGrid_SelectionChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Team Project" Binding="{Binding Path=TeamProject}" />
                            <DataGridTextColumn Header="Name" Binding="{Binding Path=WorkItemCategory.Name}" />
                            <DataGridTextColumn Header="Reference Name" Binding="{Binding Path=WorkItemCategory.RefName}" />
                            <DataGridTextColumn Header="Default Work Item Type" Binding="{Binding Path=WorkItemCategory.DefaultWorkItemType.Name}" />
                            <DataGridTextColumn Header="Other Work Item Types" Binding="{Binding Path=WorkItemTypeNames}" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <WrapPanel Grid.Row="2" Margin="0,5,0,0">
                        <Button Content="Delete Selected Work Item Categories" Command="{Binding Path=DeleteSelectedWorkItemCategoriesCommand}" />
                    </WrapPanel>
                </Grid>

            </TabItem>
            
            <TabItem Header="Update / Import" i:HelpProvider.HelpContent="Allows you to define work item categories across Team Projects, by creating them from scratch or by importing them from an existing Team Project. This can be useful if you want to change work item categories or if you want to delete work item types that are part of categories (in which case you have to remove them from any categories first).">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0">
                        <Button Content="Load From Team Project" Command="{Binding Path=LoadWorkItemCategoryListCommand}" />
                    </Grid>

                    <Grid Grid.Row="1" Margin="0,5,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="100" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Grid Grid.Column="0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ListBox Grid.Row="0" x:Name="workItemCategoriesListBox" ItemsSource="{Binding Path=SelectedWorkItemCategoryList.Categories}" SelectedItem="{Binding Path=SelectedWorkItemCategory}" DisplayMemberPath="Name" SelectionChanged="workItemCategoriesListBox_SelectionChanged" />
                            <WrapPanel Grid.Row="1">
                                <TextBlock><Hyperlink Command="{Binding Path=AddWorkItemCategoryCommand}">add</Hyperlink></TextBlock>
                                <TextBlock Margin="5,0,0,0"><Hyperlink Command="{Binding Path=RemoveSelectedWorkItemCategoryCommand}">remove</Hyperlink></TextBlock>
                            </WrapPanel>
                        </Grid>

                        <Grid Grid.Column="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Label Grid.Row="0" Grid.Column="0" Content="Name" />
                            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=SelectedWorkItemCategory.Name}" Margin="5,0,0,0" />

                            <Label Grid.Row="1" Grid.Column="0" Content="Reference Name" Margin="0,5,0,0" />
                            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=SelectedWorkItemCategory.RefName}" Margin="5,5,0,0" />

                            <Label Grid.Row="2" Grid.Column="0" Content="Default Work Item Type" Margin="0,5,0,0" />
                            <ComboBox Grid.Row="2" Grid.Column="1" ItemsSource="{Binding Path=AvailableWorkItemTypeReferences}" SelectedItem="{Binding Path=SelectedWorkItemCategory.DefaultWorkItemType}" DisplayMemberPath="Name" Margin="5,5,0,0" />

                            <Label Grid.Row="3" Grid.Column="0" Content="Other Work Item Types" Margin="0,5,0,0" />
                            <ListBox Grid.Row="3" Grid.Column="1" ItemsSource="{Binding Path=AvailableWorkItemTypeReferences}" SelectionMode="Extended" x:Name="workItemTypesListBox" SelectionChanged="workItemTypesListBox_SelectionChanged" Margin="5,5,0,0" HorizontalContentAlignment="Stretch">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" IsEnabled="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsEnabled}" Content="{Binding Path=Name}" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </Grid>

                    </Grid>

                    <Grid Grid.Row="2" Margin="0,5,0,0">
                        <Button Content="Import Work Item Categories" Command="{Binding Path=ImportWorkItemCategoryListCommand}" />
                    </Grid>

                </Grid>

            </TabItem>

        </TabControl>

    </Grid>
</UserControl>